//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Validation Application Block
//===============================================================================

using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design.ValidatorNodes;
using EntLibContrib.Validation.Configuration.Design.Properties;

namespace EntLibContrib.Validation.Configuration.Design.Nodes
{
	/// <summary>
	/// Composite RuleSet Validator Node
	/// </summary>
	public class CompositeRuleSetValidatorNode : SingleValidatorNodeBase
	{
		#region Fields
		private string targetRuleSets;
		private ValidationSpecificationSource source;
		private string configurationSourceName;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the source.
		/// </summary>
		/// <value>The source.</value>
		[SRCategory("CategoryGeneral", typeof(Resources))]
		[SRDescription("DescriptionSource", typeof(Resources))]
		public ValidationSpecificationSource Source
		{
			get { return source; }
			set { source = value; }
		}

		/// <summary>
		/// Gets or sets the name of the configuration source.
		/// </summary>
		/// <value>The name of the configuration source.</value>
		[SRCategory("CategoryGeneral", typeof(Resources))]
		[SRDescription("DescriptionConfigurationSourceName", typeof(Resources))]
		public string ConfigurationSourceName
		{
			get { return configurationSourceName; }
			set { configurationSourceName = value; }
		}

		/// <summary>
		/// Gets or sets the target rule sets.
		/// </summary>
		/// <value>The target rule sets.</value>
		[SRCategory("CategoryGeneral", typeof(Resources))]
		[SRDescription("DescriptionTargetRuleSets", typeof(Resources))]
		public string TargetRuleSets
		{
			get { return targetRuleSets; }
			set { targetRuleSets = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="CompositeRuleSetValidatorNode"/> class.
		/// </summary>
		public CompositeRuleSetValidatorNode()
			: this(new CompositeRuleSetValidatorData(Resources.CompositeRuleSetValidatorNodeName))
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="CompositeRuleSetValidatorNode"/> class.
		/// </summary>
		/// <param name="validatorData">The validator data.</param>
		public CompositeRuleSetValidatorNode(CompositeRuleSetValidatorData validatorData)
			: base(validatorData)
		{
			targetRuleSets = validatorData.TargetRuleSets;
			source = validatorData.Source;
			configurationSourceName = validatorData.ConfigurationSourceName;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// When overriden in a derived class, this method returns the runtime configuration data represented by this node.
		/// </summary>
		/// <returns>
		/// The runtime configuration data represented by this node, that can de persisted to a configuration file.
		/// </returns>
		public override ValidatorData CreateValidatorData()
		{
			CompositeRuleSetValidatorData validatorData = new CompositeRuleSetValidatorData(Name);

			validatorData.TargetRuleSets = TargetRuleSets;
			validatorData.Source = Source;
			validatorData.ConfigurationSourceName = ConfigurationSourceName;

			return validatorData;
		}
		#endregion
	}
}
